package com.gitpractice.liwushuo.fragment;


import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.gitpractice.liwushuo.R;
import com.gitpractice.liwushuo.adapter.HotVpAdapter;

import java.util.ArrayList;
import java.util.List;

import butterknife.ButterKnife;

/**
 * A simple {@link Fragment} subclass.
 */
public class ProfileFragment extends Fragment {
    private TabLayout tabLayout;
    private ViewPager viewPager;
    private List<Fragment> mFragments;
    private List<String> mTabs;

    public ProfileFragment() {
        // Required empty public constructor
    }


    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mFragments=new ArrayList<>();
        mTabs=new ArrayList<>();

    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_profile, container, false);
        return view;
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        tabLayout= (TabLayout) view.findViewById(R.id.tl_two);
        viewPager= (ViewPager) view.findViewById(R.id.vp_content);
        initData();
    }



    private void initData() {
        mFragments = new ArrayList<>();
        mTabs = new ArrayList<>();
        tabLayout.setupWithViewPager(viewPager);
        mTabs.add("单品");
        mTabs.add("攻略");
        mFragments.add(ProfileSingleFragment.newInstance());
        mFragments.add(ProfileStrategyFragment.newInstance());
        viewPager.setAdapter(new HotVpAdapter(getFragmentManager(), mFragments));
        Log.i("123","@@@@@@"+mTabs);
        for (int i = 0; i <mTabs.size(); i++) {
            TabLayout.Tab tab = tabLayout.getTabAt(i);
            tab.setText(mTabs.get(i));
            Log.i("123",tab.getText().toString()+"$$$$$");
        }
    }
    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.reset(this);
    }
}
